﻿@model byte[]
@{
    Dictionary<string, object> htmlAttr = new Dictionary<string, object>();
    if (null != ViewData["htmlAttributes"])
    {
        var properties = ViewData["htmlAttributes"].GetType().GetProperties().ToList();
        properties.ForEach(p => htmlAttr.Add(p.Name, p.GetValue(ViewData["htmlAttributes"]).ToString()));
    }
    Guid id = Guid.NewGuid();
    string fileId = ViewData.TemplateInfo.GetFullHtmlFieldId("");
    htmlAttr.Add("id", fileId);
    htmlAttr.Add("accept", "image/*");
    var imageViewerId = fileId + id.ToString() + "_ImageView";
}
@Html.FileFor(model => model, htmlAttributes: htmlAttr)
@Html.ImageContentFor(model => model, new { id = imageViewerId ,style= "max-height:200px;max-width:200px" })
<script src="~/Scripts/imageviewer.js"></script>
<script>
    $("#@(fileId)").change(function () {
        var objUrl = getObjectURL(this.files[0]);
        //console.log("objUrl = " + objUrl);
        if (objUrl) {
            $("#@(imageViewerId)").attr("src", objUrl);
        }
    });
</script>